#ifndef __METAINFO_H__
#define __METAINFO_H__ 

#include "xx.h"

#define MAX_FILE_NUM		100
#define MAX_PATH_NUM		10		// the num of sub strings in a path
#define MAX_ANNOUNCE_NUM	50

typedef struct file{
	int			  length;			// must
	char		* md5sum;
	char		**path;				// must
	char		**path_utf8;		// must
	char		* ed2k;		
	char		  filehash[21];		
}xx_file;

struct metainfo{
	char			* announce;			// must
	char			**announce_list;
	int				  creat_date;
	char			* comment;
	char			* creat_by;
	char			* encoding;
	//	aditional
	char			* publ;				// publisher 
	char			* publ_utf8;		// publisher.utf-8 
	char			* publ_url;			// publisher-url 
	char			* publ_url_utf8;	// publisher-url.utf-8 

	/********** Info dict **********/
	int				  info_mode;		// 0 --single, 1 --multile
	int				  piece_len;		// must
	char			* pieces/*[20]*/;	// must
	int				  privat;

	// files
	char			* name;				// must
	char			* name_utf8;		// name.utf-8 
	xx_file			* files;
	int				  files_num;		// used to record the number of xx_file

	// SHA1 of info
	unsigned char	  hash_str[20];
};


int parse_metainfo(char *buffer, int buff_len, xx_metainfo *meta);

int parse_file_info(benc *dict, xx_metainfo *meta);

int parse_file_list(benc *list, xx_metainfo *meta);

int parse_announce_list(benc *list, xx_metainfo *meta);	//  todo

int	free_metainfo(xx_metainfo *meta);

int	show_metainfo(xx_metainfo *meta);
#endif

